package cn.lingyangwl.agile.food.core.controller.admin;

import cn.lingyangwl.agile.food.model.rqrs.store.*;
import cn.lingyangwl.agile.ram.ActionType;
import cn.lingyangwl.agile.ram.RamResource;
import cn.lingyangwl.agile.food.core.service.StoreService;
import cn.lingyangwl.framework.core.response.Resp;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 门店
 * 
 * @author shenguangyang
 */
@Api(tags = "门店")
@RestController
@RequestMapping("/store")
public class ShopStoreController {
    @Resource
    private StoreService storeService;

    @ApiOperation(value = "分页门店")
    @PostMapping("/setting")
    @RamResource(action = "shopStore:store:setting", name = "门店设置", type = ActionType.WRITE)
    public Resp<?> storeSetting(@RequestBody @Validated StoreSettingReq req) {
        storeService.storeSetting(req);
        return Resp.ok();
    }

    @ApiOperation(value = "分页门店")
    @GetMapping("/pageStore")
    @RamResource(action = "shopStore:store:query", name = "查询门店", type = ActionType.READ)
    public Resp<IPage<StoreResp>> pageStore(@Validated StorePageReq req) {
        return Resp.ok(storeService.pageStore(req));
    }

    @ApiOperation(value = "查询全部门店")
    @GetMapping("/listStore")
    @RamResource(action = "shopStore:store:query", name = "查询门店", type = ActionType.READ)
    public Resp<List<StoreResp>> listStore(StoreListReq req) {
        return Resp.ok(storeService.listStore(req));
    }

    @ApiOperation(value = "通过id查找门店")
    @GetMapping("/getStore")
    @RamResource(action = "shopStore:store:query", name = "查询门店", type = ActionType.READ)
    public Resp<StoreResp> getStore(@RequestParam(value = "id") String id) {
        return Resp.ok(storeService.getStore(id));
    }
  
    @ApiOperation(value = "保存门店")
    @PostMapping("/saveStore")
    @RamResource(action = "shopStore:store:save", name = "保存门店", type = ActionType.WRITE)
    public Resp<?> saveStore(@Validated @RequestBody StoreSaveReq req) {
        return Resp.ok(storeService.saveStore(req));
    }
  
    @ApiOperation(value = "更新门店")
    @PostMapping("/updateStore")
    @RamResource(action = "shopStore:store:update", name = "更新门店", type = ActionType.WRITE)
    public Resp<?> updateStore(@Validated @RequestBody StoreUpdateReq req) {
        return Resp.ok(storeService.updateStore(req));
    }
  
    @ApiOperation(value = "批量删除门店")
    @DeleteMapping("/batchDeleteStore")
    @RamResource(action = "shopStore:store:delete", name = "删除门店", type = ActionType.WRITE)
    public Resp<?> batchDeleteStore(@RequestParam(value = "ids") List<Long> ids) {
        return Resp.ok(storeService.batchDeleteStore(ids));
    }
  
    @ApiOperation(value = "删除门店")
    @DeleteMapping("/deleteStore")
    @RamResource(action = "shopStore:store:delete", name = "删除门店", type = ActionType.WRITE)
    public Resp<?> deleteStore(@RequestParam(value = "id") Long id) {
        return Resp.ok(storeService.deleteStore(id));
    }
}
